package com.be.beadmin.service.controller;

import com.be.beadmin.common.entity.PageEntity;
import com.be.beadmin.common.utils.ResultModel;
import com.be.beadmin.service.dto.input.DictDataDto;
import com.be.beadmin.service.dto.input.DictTypeDataDto;
import com.be.beadmin.service.entity.DictTypeEntity;
import com.be.beadmin.service.service.DictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
* @author zjm
* @date 2023-02-02
**/
@RestController
@Api(tags = "字典数据内容")
public class DictDataController {

    @Autowired
    private  DictDataService dictDataService;

    @ApiOperation("获取字典数据分页信息")
    @PostMapping(value = "/service/getDictDataByPage")
    public ResultModel getDictDataByPage(@RequestBody PageEntity pageEntity)  {
        return ResultModel.success(dictDataService.getDictDataByPage(pageEntity)) ;
    }
    @ApiOperation("根据字典类型获取字典数据分页信息")
    @PostMapping(value = "/service/getDictDataByPageAndDictType")
    public ResultModel getDictDataByPageAndDictType(@RequestBody DictTypeEntity pageEntity)  {
        return ResultModel.success(dictDataService.getDictDataByPageAndDictType(pageEntity)) ;
    }
    @ApiOperation("添加一条字典数据")
    @PostMapping("/service/addDictData")
    public ResultModel addDictData(@RequestBody DictDataDto dictDataDto){
        dictDataService.addDictData(dictDataDto);
        return ResultModel.success(ResultModel.ADD);
    }
    @ApiOperation("添加一条字典数据通过Id")
    @PostMapping("/service/addDictDataByDictTypeId")
    public ResultModel addDictDataByDictTypeId(@RequestBody DictTypeDataDto dictDataDto){
        dictDataService.addDictDataByDictTypeId(dictDataDto);
        return ResultModel.success(ResultModel.ADD);
    }
    @ApiOperation("删除一条字典数据")
    @PostMapping("/service/delDictData")
    public ResultModel delDictData(@RequestBody DictDataDto dictDataDto){
        dictDataService.delDictData(dictDataDto.getId());
        return ResultModel.success(ResultModel.DELETE);
    }

    @ApiOperation("更新一条字典数据")
    @PostMapping("/service/updateDictData")
    public ResultModel updateDictData(@RequestBody DictDataDto dictDataDto){
        dictDataService.updateDictData(dictDataDto);
        return ResultModel.success(ResultModel.UPDATE);
    }
}